- /* sdmround.cpp by K.Tsuru */
- // function ID = 342 DRADIX, BRADIX
- /******************************************************************************
- SDouble class
- It provides the rounding off to the last effective figure.
- At the top of hidden figures it rounds up numbers of radix/2 and above and drops
- anything under radix/2.It is used in the output function, etc.
- It executes in the case size==MaxSize(). It does not use CurrentMaxSize().
- When std==1 it converts into the standard from.
- default : std = 1
- *******************************************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
-
- SDouble& SDouble::Round(int std){
- //conversion into standard form, SDouble only
- if( (Type() == REAL) && (std & STD_REF) ) StdReform(342);
- // 0.v[1] ...... v[eff]v[hdn]
- uint i, eff = MaxSize() - Hidden() -1u, rnd;
- if(aHead <= eff) return *this; //It has no hidden figure including 0.
- rnd = eff + 1u; //top position of the hidden figures
-
- if( figure(rnd) >= Radix()/2 ){
- figure[rnd-1]++;
- if(figure(rnd-1) >= Radix()) Normalize();
- if(figure(0) && (Type() == REAL)){
- // 0.99999....D^e --> 1.0000....D^e --> 0.1000.... D^(e+1)
- SetRdxExp(rdxExp+1); ShiftArray(1);
- }
- }
- //It cuts down the hidden figures.
- for(i = rnd; i<= aHead; i++) figure[i] = 0;
- if(aTail >= rnd){
- //It becomes zero by cutting down in the fixed point mode.
- SetZero(); return *this;
- }
- //It gets the figure positions."aTail" is not changed.
- i = rnd-1;
- const fType* fp = figure.Elements();
- while( !fp[i] ) i--;
- #ifndef NDEBUG
- figure(i);
- #endif
- aHead = i;
-
- //It converts into the standard form again for the reduction of the size, etc.
- //0.abcd efgh 0000 .... 0000 hhhh hhhh --> 0.abcd efgh 0000 .... 0000
- if( (Type() == REAL) && (std & STD_REF) ) StdReform(342);
- return *this;
- }
sdmround.cpp : last modifiled at 2017/03/13 14:31:57(1,850 bytes)
created at 2017/10/07 10:21:15
The creation time of this html file is 2017/10/07 10:30:03 (Sat Oct 07 10:30:03 2017).